home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Interapplication Communication / IPCLister / IPCLister.main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-09  |  26.0 KB  |  704 lines  |  [TEXT/MPS ]

  1. /* IPCLister.c */
  2. /* The simplest C System 7 shell application */
  3. /* Modified to show IPCListPorts */
  4. /* March, 1992 */
  5. /* C.K. Haun <TR> */
  6. /* This shell can be very handy for debugging and testing things */
  7. /* Add menu items, add dialogs, add controls, or whatever else you need */
  8. /* This sample contains basic application startup and event loop handling, */
  9. /* add more features as your needs increase. */
  10. /* This sample is High Level Event aware, so you can send and receive AppleEvents */
  11. /* from this application */
  12. /* Written by C.K. Haun <TR> */
  13. /* Apple Developer Tech Support */
  14. /* October 1991, Tokyo, Japan */
  15. /* Of course, Copyright 1991-1992, Apple Computer Inc. */
  16.  
  17. #include <Types.h>
  18. #include <memory.h>
  19. #include <Packages.h>
  20. #include <Errors.h>
  21. #include <quickdraw.h>
  22. #include <fonts.h>
  23. #include <dialogs.h>
  24. #include <windows.h>
  25. #include <menus.h>
  26. #include <events.h>
  27. #include <OSEvents.h>
  28. #include <Desk.h>
  29. #include <diskinit.h>
  30. #include <OSUtils.h>
  31. #include <resources.h>
  32. #include <toolutils.h>
  33. #include <AppleEvents.h>
  34. #include <EPPC.h>
  35. #include <GestaltEqu.h>
  36. #include <PPCToolbox.h> 
  37. #include <Processes.h>
  38. #include <Balloons.h>
  39. #include <ALiases.h>
  40. #include <Processes.h>
  41. #include <StandardFile.h>
  42. #include <Folders.h>
  43. #include <AppleTalk.h> 
  44. #include <Lists.h>
  45. /* prototypes */
  46. void InitalizeApp(void);
  47. void DoDiskEvents(long dinfo);                              /* hi word is error code, lo word is drive number */
  48. void DrawMain(WindowPtr drawIt);
  49. Boolean DoSelected(long val);
  50. void InitAEStuff(void);
  51. void DoHighLevel(EventRecord *AERecord);
  52. void DoDaCall(MenuHandle themenu, long theit);
  53. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  54. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  55. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  56. pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
  57. void SampleHelpDialog(void);
  58. void RefreshMacList(ListHandle theList);
  59. void DoIPCListAndFillList(Cell *theCell, ListHandle theList);
  60. void SetContextSwitch(Boolean how);
  61. OSErr myGetMyZone(char *nameBack);
  62.  
  63.  
  64. /*  external */
  65. extern void _DataInit();                                    /* this is the C initialization code */
  66. extern OSErr myIPCListPorts(short theStartIndex, short theRequestCount, short *theActualCount, Str32 theObjStr, Str32 theZoneStr,
  67.                             PortInfoArrayPtr thePortInfoBufferPtr);
  68. extern OSErr GetAllPPCAbleMachines(MPPParamBlock *paramblk);
  69. extern OSErr GetPortsOnMachine();
  70. extern MPPParamBlock paramblk;
  71.  
  72.  
  73.  
  74. enum  {
  75.     kMBarID = 128
  76. };
  77. enum  {
  78.     kAppleMenu = 128, kFileMenu, kEditMenu, kToolsMenu
  79. };
  80. enum  {
  81.     kResumeMask = 1,  /* bit of message field for resume vs. suspend */
  82.     kSampHelp = 129, kAboutBox = 128, kHelpString = 128, kNewItem = 1, kOpenItem, kCloseItem,
  83.     kSaveItem, kSaveAsItem, kFileBlank1,
  84.         kPageSetupItem, kPrintItem, kFileBlank2, kQuitItem, 
  85.         kBadSystem = 130, kGenStrings = 128, kMenuToggleStrings = 129,
  86.         kMyModalKind = 1000, kMyDocumentKind
  87. };
  88. enum  {
  89.     kItem1 = 1, kWaitDialog = 131
  90. };
  91. enum  {
  92.     kCloseIt = 1, kOpenIt
  93. };
  94. /* string IDs for window */
  95. enum  {
  96.     kSayMacs = 2, kSayPorts = 3
  97. };
  98.  
  99. /* some globals */
  100. MenuHandle gAppleMenuHandle, gFileMenuHandle, gEditMenuHandle, gToolMenuHandle;
  101. Boolean gQuit, gInBackground;
  102. EventRecord gERecord;
  103. AEDesc gTheAddress;
  104. ProcessSerialNumber gOurSN;
  105. short gHelpItem;
  106. /* this is our global to tell us if a movable modal is up*/
  107. unsigned long gMySleep = 30;
  108. ListHandle gMacList, gPortsList;
  109.  
  110. #ifdef powerc
  111.    QDGlobals    qd;
  112. #endif
  113.  
  114. #pragma segment Main
  115. main()
  116. {
  117.     WindowPtr twindow;
  118.     UnloadSeg((Ptr)_DataInit);                              /* throw out setup code */
  119.     InitalizeApp();
  120.     UnloadSeg((Ptr)InitalizeApp);   /* get rid of my initialization code */
  121.     do {
  122.         
  123.         WaitNextEvent(everyEvent, &gERecord, gMySleep, nil);
  124.         switch (gERecord.what) {
  125.             ProcPtr drawProc;
  126.             short tempKind;
  127.             case nullEvent:
  128.                 /* no nul processing in this sample */
  129.                 break;
  130.                 
  131.             case updateEvt:
  132.                 tempKind = ((WindowPeek)gERecord.message)->windowKind;
  133.                 /* Mkae sure it's my window before I jump through the refCon */
  134.                 /* Why, since DA's have they're own layer in 7.0? */
  135.                 /* BECAUSE there are other people in the universe who will */
  136.                 /* add things to your windowList.BalloonWriter, for example, */
  137.                 /* so you still need to be careful */
  138.                 if (tempKind == kMyModalKind || tempKind == kMyDocumentKind) {
  139.                     /* get the drawing proc from the refCon */
  140.                     drawProc = (ProcPtr)GetWRefCon((WindowPtr)gERecord.message);
  141.                     /* jump to it */
  142.                     drawProc((WindowPtr)gERecord.message);
  143.                 }
  144.                 break;
  145.                 
  146.             case mouseDown:
  147.                 /* first see where the hit was */
  148.                 
  149.                 switch (FindWindow(gERecord.where, &twindow)) {
  150.                     
  151.                     case inDesk:                            /* if they hit in desk, then the process manager */
  152.                         break;                              /* will switch us out, we don't need to do anything */
  153.                         
  154.                     case inMenuBar:
  155.                         /* let Help and Application menus happen always */
  156.                         DoSelected(MenuSelect(gERecord.where));
  157.                         break;
  158.                         
  159.                     case inSysWindow:
  160.                         /* pass to the system */
  161.                         SystemClick(&gERecord, twindow);
  162.                         break;
  163.                         
  164.                     case inContent:
  165.                         /* Handle content and control clicks here */
  166.                         /* If they clicked in the content region of a back window, */
  167.                         /* bring that window forward */
  168.                         if (twindow != FrontWindow()) {                            
  169.                             SelectWindow(twindow);          /* select the window */
  170.                             SetPort(twindow);                            
  171.                         } else {
  172.                             /* control tracking or whatever. */
  173.                             /* Here we have a couple of lists, so we'll track */
  174.                             /* them */
  175.                             Rect boundRect;
  176.                             Point locPoint = gERecord.where;
  177.                              GlobalToLocal(&locPoint);
  178.                             /* first see if it's in eiher of our Lists */
  179.                             boundRect = (*gMacList)->rView;
  180.                             /* expand to include the scroll bear */
  181.                             boundRect.right += 15;
  182.                             if (PtInRect(locPoint, &boundRect)) {
  183.                                 Cell currentCell =  {
  184.                                     0, 0
  185.                                 };
  186.                                 Cell theCell =  {
  187.                                     0, 0
  188.                                 };
  189.                                 /* first, get the current cell */
  190.                                 LGetSelect(true, ¤tCell, gMacList);
  191.                                 if (LClick(locPoint, nil, gMacList)) {                                    
  192.                                     /* if it's in this list, switch port list */
  193.                                     if (LGetSelect(true, &theCell, gMacList)) {
  194.                                         /* this is where you'd do something special for a double-click */
  195.                                         /* in this example I just fill the other list in agin */
  196.                                         DoIPCListAndFillList(&theCell, gPortsList);
  197.                                     }
  198.                                 } else {
  199.                                     /* single click, but maybe they changed things */
  200.                                     LGetSelect(true, &theCell, gMacList);
  201.                                     if (theCell.v != currentCell.v)
  202.                                         DoIPCListAndFillList(&theCell, gPortsList);
  203.                                 }
  204.                             } else {
  205.                                 boundRect = (*gPortsList)->rView;
  206.                                 /* expand to include the scroll bear */
  207.                                 boundRect.right += 15;
  208.                                 
  209.                                 if (PtInRect(locPoint, &boundRect)) {
  210.                                     LClick(locPoint, nil, gPortsList);
  211.                                     /* if it's in this list, I just don't care atall */
  212.                                 } else {
  213.                                     /* normal control tracking goes here, commented out */
  214.                                     /* since I'm not using it today */
  215.                                     /*
  216.                                     if (FindControl(locPoint, twindow, &returnedControl)) {
  217.                                     if (TrackControl(returnedControl, locPoint, nil)) {
  218.                                     
  219.                                     }
  220.                                     } */
  221.                                 }
  222.                             }
  223.                         }
  224.                         break;
  225.                         
  226.                     case inDrag:
  227.                         DragWindow(twindow, gERecord.where, &qd.screenBits.bounds);
  228.                         break;
  229.                         
  230.                     case inGrow:
  231.                         /* Call GrowWindow here if you have a grow box */
  232.                         break;
  233.                         
  234.                     case inGoAway:
  235.                         /* Click in Close box */
  236.                         break;
  237.                 }
  238.             case mouseUp:
  239.                 /* don't care */
  240.                 break;
  241.                 /* same action for key or auto key */
  242.             case keyDown:
  243.             case autoKey:
  244.                 if (gERecord.modifiers & cmdKey)
  245.                     DoSelected(MenuKey(gERecord.message & charCodeMask));
  246.                 break;
  247.                 
  248.             case keyUp:
  249.                 /* don't care */
  250.                 break;
  251.                 
  252.             case diskEvt:
  253.                 /* I don't do anything special for disk events, this just passes them */
  254.                 /* to a function that checks for an error on the mount */
  255.                 DoDiskEvents(gERecord.message);
  256.                 break;
  257.                 
  258.             case activateEvt:
  259.                 /* not doing anything on activates */
  260.                 break;
  261.                 
  262.             case networkEvt:
  263.                 /* don't care */
  264.                 break;
  265.                 
  266.             case driverEvt:
  267.                 /* don't care */
  268.                 break;
  269.                 
  270.             case app4Evt:
  271.                 /* If we're switching layers and I have my MModal up, I want to */
  272.                 /* change the state of the control */
  273.                 switch ((gERecord.message >> 24) & 0x0FF) {     /* high byte of message */
  274.                     
  275.                     case suspendResumeMessage:              /* suspend/resume is also an activate/deactivate */
  276.                         gInBackground = (gERecord.message & kResumeMask) == 0;
  277.                         /* set dim/enable on the control */
  278.                         /* make sure hiliting is right */
  279.                         SetContextSwitch(gInBackground);
  280.                         break;
  281.                         
  282.                 }
  283.                 break;
  284.                 
  285.                 /* This dispatches high level events (AppleEvents, for example) */
  286.                 /* to our dispatch routine.This is NEW in the event loop for */
  287.                 /* System 7 */
  288.             case kHighLevelEvent:
  289.                 DoHighLevel(&gERecord);
  290.                 break;
  291.             default:
  292.                 break;
  293.                 
  294.         }
  295.     }
  296.             while (gQuit != true);
  297. }
  298.  
  299. /* DoDaCall opens the requested DA.It's here as a seperate routine if you'd */
  300. /* like to perform some action or just know when a DA is opened in your */
  301. /* layer.Can be handy to track memory problems when a DA is opened */
  302. /* with an Option-open */
  303. void DoDaCall(MenuHandle themenu, long theit)
  304. {
  305.     long qq;
  306.     char DAname[255];
  307.     GetItem(themenu, theit, &DAname);
  308.     qq = OpenDeskAcc(DAname);
  309. }
  310.  
  311. /* end DoDaCall */
  312.  
  313. /* DoDiskEvents just checks the error code from the disk mount, */
  314. /* and puts up the 'Format' dialog (through DIBadMount) if need be */
  315. /* You can do much more here if you care about what disks are */
  316. /* in the drive */
  317. void DoDiskEvents(long dinfo)                               /* hi word is error code, lo word is drive number */
  318. {
  319.     short hival, loval, tommy;
  320.     Point fredpoint =  {
  321.         40, 40
  322.     };
  323.     hival = HiWord(dinfo);
  324.     loval = LoWord(dinfo);
  325.     if (hival != noErr)                                     /* something happened */ {
  326.         tommy = DIBadMount(fredpoint, dinfo);
  327.     }
  328. }
  329.  
  330. /* draws my window.Pretty simple */
  331. void DrawMain(WindowPtr drawIt)
  332. {
  333.     WindowPtr tempWP;
  334.     Str255 words;
  335.     Rect tempRect;
  336.     GetPort(&tempWP);
  337.     BeginUpdate(drawIt);
  338.     SetPort(drawIt);
  339.     EraseRect(&drawIt->portRect);
  340.     LUpdate(drawIt->visRgn, gMacList);
  341.     tempRect = (*gMacList)->rView;
  342.     InsetRect(&tempRect, -2, -1);
  343.     FrameRect(&tempRect);
  344.     MoveTo(tempRect.left, tempRect.top - 2);
  345.     GetIndString(words, kGenStrings, kSayMacs);
  346.     DrawString(words);
  347.     /* other list */
  348.     LUpdate(drawIt->visRgn, gPortsList);
  349.     tempRect = (*gPortsList)->rView;
  350.     InsetRect(&tempRect, -2, -1);
  351.     FrameRect(&tempRect);
  352.     MoveTo(tempRect.left, tempRect.top - 2);
  353.     GetIndString(words, kGenStrings, kSayPorts);
  354.     DrawString(words);
  355.     
  356.     EndUpdate(drawIt);
  357.     SetPort(tempWP);
  358. }
  359.  
  360. /* my menu action taker.It returns a Boolean which I usually ignore, but it */
  361. /* mught be handy someday */
  362. Boolean DoSelected(long val)
  363. {
  364.     short loval, hival;
  365.     Boolean returnVal = false;
  366.     loval = LoWord(val);
  367.     hival = HiWord(val);
  368.     
  369.     switch (hival) {                                        /* switch off the menu number selected */
  370.         case kAppleMenu:                                    /* Apple menu */
  371.             if (loval != 1) {                               /* if this was not About, it's a DA */
  372.                 DoDaCall(gAppleMenuHandle, loval);
  373.             } else {
  374.                 Alert(kAboutBox, nil);                      /* do about box */
  375.             }
  376.             returnVal = true;
  377.             break;
  378.         case kFileMenu:                                     /* File menu */
  379.             switch (loval) {
  380.                 case kQuitItem:
  381.                     gQuit = true;                           /* onlyitem */
  382.                     returnVal = true;
  383.                     break;
  384.                 default:
  385.                     break;
  386.             }
  387.             break;
  388.             
  389.         case kEditMenu:
  390.             /* edit menu junk */
  391.             /* don't care */
  392.             break;
  393.             
  394.         case kToolsMenu:
  395.             /* add all your test stuff here */
  396.             RefreshMacList(gMacList);
  397.             break;
  398.             
  399.         case kHMHelpMenuID:                                 /* Defined in Balloons.h */
  400.             /* I only care about this item.If anything else is returned here, I don't know what */
  401.             /* it is, so I leave it alone.Remember, the Help Manager chapter says that */
  402.             /* Apple reserves the right to add and change things in the Help menu */
  403.             if (loval == gHelpItem)
  404.                 SampleHelpDialog();
  405.             break;
  406.             
  407.     }
  408.     HiliteMenu(0);
  409.     return(returnVal);
  410. }
  411.  
  412. /* InitAEStuff installs my appleevent handlers */
  413. void InitAEStuff(void)
  414. {    
  415.     OSErr aevtErr = noErr;
  416.     long aLong = 0;
  417.     Boolean gHasAppleEvents = false;
  418.     /* Check this machine for AppleEvents.  If they are not here (ie not 7.0)
  419.     *   then we exit */
  420.     gHasAppleEvents = (Gestalt(gestaltAppleEventsAttr, &aLong) == noErr);
  421.     /* The following series of calls installs all our AppleEvent Handlers.
  422.     *   These handlers are added to the application event handler list that 
  423.     *   the AppleEvent manager maintains.  So, whenever an AppleEvent happens
  424.     *   and we call AEProcessEvent, the AppleEvent manager will check our
  425.     *   list of handlers and dispatch to it if there is one.
  426.     */
  427.     if (gHasAppleEvents) {
  428.          aevtErr = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, 
  429.              NewAEEventHandlerProc(AEOpenHandler),0, false);
  430.          aevtErr = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, 
  431.              NewAEEventHandlerProc(AEOpenDocHandler),0, false);
  432.          aevtErr = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, 
  433.              NewAEEventHandlerProc(AEQuitHandler), 0, false);
  434.          aevtErr = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, 
  435.              NewAEEventHandlerProc(AEPrintHandler),0, false);
  436.              
  437.          if (aevtErr)  ExitToShell();
  438.          
  439.  
  440.        } 
  441.     else ExitToShell();
  442.     
  443. }
  444. /* end InitAEStuff */
  445.  
  446.  
  447. /* I'm not doing error handling in this sample for clarities sake, you should. Hah, */
  448. /* easy for me to say, huh? */
  449. void DoHighLevel(EventRecord *AERecord)
  450. {
  451.     
  452.     AEProcessAppleEvent(AERecord);
  453.     
  454. }
  455.  
  456. /* end DoHighLevel */
  457.  
  458. /* This is the standard Open Application event.*/
  459. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  460. {
  461. #pragma unused (messagein,reply,refIn)
  462.  
  463.     Rect lRect;
  464.     Rect lRect2 =  {
  465.         0, 0, 0, 1
  466.     };
  467.     Point cp =  {
  468.         0, 0
  469.     };
  470.     
  471.     short theSize;
  472.     FontInfo theFont;
  473.     typedef unsigned char Tuple[104];
  474.     extern Tuple myRetBuff[100];
  475.     WindowPtr myWindow;
  476.     /* we of course don't do anything here in this simple app */
  477.     /* except open our window */
  478.     myWindow = GetNewWindow(128, nil, (WindowPtr)-1);
  479.     ((WindowPeek)myWindow)->windowKind = kMyDocumentKind;
  480.     /* install drawing proc */
  481.     SetWRefCon(myWindow, (long)DrawMain);
  482.     
  483.     /* add two lists */
  484.     SelectWindow(myWindow);
  485.     SetPort(myWindow);
  486.     /* call the draw proc oncet */
  487.     GetFontInfo(&theFont);
  488.     theSize = (theFont.ascent + theFont.descent + theFont.leading) * 10;
  489.     SetRect(&lRect, 10, 30, (myWindow->portRect.right / 2) - 15, 30 + theSize);
  490.     gMacList = LNew(&lRect, &lRect2, cp, nil, myWindow, true, false, false, true);
  491.     LActivate(true, gMacList);
  492.     LDoDraw(false, gMacList);
  493.     (*gMacList)->listFlags = lDoVAutoscroll;
  494.     SetRect(&lRect, (myWindow->portRect.right / 2) + 15, 30, (myWindow->portRect.right) - 15, 30 + theSize);
  495.     
  496.     gPortsList = LNew(&lRect, &lRect2, cp, nil, myWindow, true, false, false, true);
  497.     LActivate(true, gPortsList);
  498.     LDoDraw(false, gPortsList);
  499.     (*gPortsList)->listFlags = lDoVAutoscroll;
  500.     /* While we're here we may as well find and add all the PPC capable macs in my zone */
  501.     DrawMain(myWindow);
  502.     
  503.     RefreshMacList(gMacList);
  504.     
  505.     return(noErr);
  506.     
  507. }
  508.  
  509. /* end AEOpenHandler */
  510.  
  511. /* Open Doc, opens our documents.Remember, this can happen at application start AND */
  512. /* anytime else.If your app is up and running and the user goes to the desktop, hilites one */
  513. /* of your files, and double-clicks or selects Open from the finder File menu this event */
  514. /* handler will get called. Which means you don't do any initialization of globals here, or */
  515. /* anything else except open then doc.*/
  516. /* SO-- Do NOT assume that you are at app start time in this */
  517. /* routine, or bad things will surely happen to you. */
  518.  
  519. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  520. {
  521. #pragma unused (messagein,refIn,reply)
  522.     /* we of course don't do anything here */
  523.     return(errAEEventNotHandled);                           /* we have no docs, so no odoc events should come to us */
  524. }
  525.  
  526. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  527. {                                                           /* no printing handler in yet, so we'll ignore this */
  528.     /* the operation is functionally identical to the ODOC event, with the additon */
  529.     /* of calling your print routine.*/
  530. #pragma unused (messagein,refIn,reply)
  531.     /* we of course don't do anything here */
  532.     return(errAEEventNotHandled);                           /* we have no docs, so no pdoc events should come to us */
  533. }
  534.  
  535. /* Standard Quit event handler, to handle a Quit event from the Finder, for example.*/
  536. /* ••••• DO NOT CALL EXITTOSHELL HERE ••••• or you will never have a happy life.*/
  537. pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  538. {
  539. #pragma unused (messagein,refIn,reply)
  540.     
  541.     /* prepQuit sets the Stop flag for us.It does _NOT_ quit, you */
  542.     /* should NEVER quit from an AppleEvent handler.Calling */
  543.     /* ExitToShell here would blow things up */
  544.     gQuit = true;
  545.     return(noErr);
  546. }
  547.  
  548. /* This is my sample help dialog.Does not do anything, expand as you need */
  549. void SampleHelpDialog(void)
  550. {
  551.     DialogPtr tdial = GetNewDialog(kSampHelp, nil, (WindowPtr)-1);
  552.     short itemhit = 0;
  553.     while (itemhit != 1) {
  554.         ModalDialog((ModalFilterProcPtr)nil, &itemhit);
  555.     }
  556.     DisposeDialog(tdial);
  557. }
  558.  
  559.  
  560. /* myGetMyZone returns (oh, you guessed!) a zone name string */
  561. OSErr myGetMyZone(char *nameBack)
  562. {
  563.     OSErr myErr = noErr;
  564.     XPPParamBlock *theParamPtr = (XPPParamBlock *)NewPtrClear(sizeof(XPPParamBlock));
  565.     theParamPtr->XCALL.xppTimeout = 3;
  566.     theParamPtr->XCALL.xppRetry = 4;
  567.     theParamPtr->XCALL.zipBuffPtr = nameBack;
  568.     theParamPtr->XCALL.zipInfoField[1] = 0;
  569.     theParamPtr->XCALL.zipInfoField[2] = 0;
  570.     myErr = GetMyZone(theParamPtr, false);
  571.     DisposePtr((Ptr)theParamPtr);
  572.     return(myErr);
  573. }
  574.  
  575. /* RefreshMacList re-scans the current zone for all macs, and */
  576. /* adds them to the list */
  577. void RefreshMacList(ListHandle theList)
  578. {
  579.     register qq;
  580.     Cell cp =  {
  581.         0, 0
  582.     };
  583.     /* This takes a while here at Apple (lotsa machines) so I'll put up a wait dialog */
  584.     DialogPtr theDial = GetNewDialog(kWaitDialog, nil, (WindowPtr)-1);
  585.     DrawDialog(theDial);
  586.     /* this takes a while */
  587.     SetCursor(*GetCursor(watchCursor));
  588.     /* Delete all the current list entries quickly */
  589.     LDelRow(32000, 0, theList);
  590.     /* fill in the list of machines */
  591.     GetAllPPCAbleMachines(¶mblk);
  592.     /* loop through all the machines in this zone and add 'em to the list */
  593.     for (qq = 0; qq < paramblk.NBP.parm.Lookup.numGotten; qq++) {
  594.         EntityName myEntityName;
  595.         AddrBlock myAddrBlock;   
  596.         
  597.         LAddRow(1, qq, theList);    /* a new item, add a row for it */
  598.         cp.v = qq;
  599.         /* get the info out of the NBP record.  It's easier than calculating the offsets */
  600.         /* yerself */
  601.         NBPExtract((Ptr)&myRetBuff, paramblk.NBP.parm.Lookup.numGotten, qq + 1, &myEntityName, &myAddrBlock);
  602.         /* and add this name to the list */
  603.         LAddToCell((&myEntityName.objStr[1]), myEntityName.objStr[0], cp, theList);
  604.     }
  605.     /* kill my wait dialog */
  606.     DisposeDialog(theDial);
  607.     InitCursor();
  608. }
  609.  
  610. /* DoIPCListAndFillList calls IPCListPorts for the machine name selected, and  */
  611. /* fills our list with the ports on the other machine */
  612. void DoIPCListAndFillList(Cell *theCell, ListHandle theList)
  613. {
  614.     PortInfoArrayPtr thePorts;
  615.     short returnedCount;
  616.     OSErr myErr = noErr;
  617.     Cell cp =  {
  618.         0, 0
  619.     };
  620.     EntityName myEntityName;
  621.     AddrBlock myAddrBlock;                                  /* myAddrBlock: AddrBlock; */
  622.     register qq;
  623.     SetCursor(*GetCursor(watchCursor));
  624.     /* I want to get a maximum of 30 ports, so allocate a buffer that big */    
  625.     thePorts = (PortInfoArrayPtr)NewPtrClear(sizeof(PortInfoRec) * 30);
  626.     /* extract the machine name and zone name based on the cell they clicked  */
  627.     /* on and the buffer we got from GetAllPPCAbleMachines */
  628.     NBPExtract((Ptr)&myRetBuff, paramblk.NBP.parm.Lookup.numGotten, theCell->v + 1, &myEntityName, &myAddrBlock);
  629.     /* call our IPCList routine */
  630.     myErr = myIPCListPorts(0, 30, &returnedCount, myEntityName.objStr, myEntityName.zoneStr, thePorts);
  631.     if(myErr == noErr){
  632.         /* now add the names to the list */
  633.         LDelRow(32000, 0, theList);
  634.         for (qq = 0; qq < returnedCount; qq++) {
  635.             LAddRow(1, qq, theList);
  636.             cp.v = qq;            
  637.             LAddToCell(&(((PortInfoPtr)thePorts)->name.name[1]), thePorts->name.name[0], cp, theList);
  638.             thePorts = thePorts + 1;            
  639.         }
  640.     }
  641.     DisposePtr((Ptr)thePorts);
  642.     InitCursor();
  643. }
  644.  
  645. /* SetContextSwitch does what I need to do to go into/come out of */
  646. /* the backgrounmd.  In this example, all I do is set the lists */
  647. void SetContextSwitch(Boolean how)
  648. {
  649. how = (how ? false:true); /* don't ask, The how is kinda backwards */
  650.     LActivate(how,gMacList);
  651.     LActivate(how,gPortsList);
  652. }
  653.  
  654.  
  655. #pragma segment Init
  656. void InitalizeApp(void)
  657. {
  658.     MenuHandle helpHandle;
  659.     Handle myMenu;
  660.     StringHandle helpString;
  661.     short count;
  662.     long vers;
  663.     MaxApplZone();
  664.     InitGraf((Ptr)&qd.thePort);
  665.     InitFonts();
  666.     InitWindows();
  667.     InitMenus();
  668.     TEInit();
  669.     InitDialogs(nil);
  670.     InitCursor();
  671.     /* Check system version */
  672.     Gestalt(gestaltSystemVersion, &vers);
  673.     vers = (vers >> 8) & 0xf;                               /* shift result over and mask out major version number */
  674.     if (vers < 7) {
  675.         StopAlert(kBadSystem, nil);
  676.         ExitToShell();
  677.     }
  678.     PPCInit();
  679.     InitAEStuff();
  680.     
  681.     /* set up my menu junk */
  682.     myMenu = GetNewMBar(kMBarID);
  683.     SetMenuBar(myMenu);
  684.     gAppleMenuHandle = GetMHandle(kAppleMenu);
  685.     gFileMenuHandle = GetMHandle(kFileMenu);
  686.     gEditMenuHandle = GetMHandle(kEditMenu);
  687.     gToolMenuHandle = GetMHandle(kToolsMenu);
  688.     AddResMenu(gAppleMenuHandle, 'DRVR');
  689.     /* now install my Help menu item in the Help Manager's menu */
  690.     HMGetHelpMenuHandle(&helpHandle);                       /* Get the Hlpe menu handle */
  691.     count = CountMItems(helpHandle);                        /* How many items are there? */
  692.     helpString = GetString(kHelpString);                    /* get my help string */
  693.     DetachResource(helpString);                             /* detach it */
  694.     HNoPurge(helpString);
  695.     MoveHHi((Handle)helpString);
  696.     HLock((Handle)helpString);
  697.     InsMenuItem(helpHandle, (Ptr)*helpString, count + 1);       /* insert my item in the Help menu */
  698.     gHelpItem = CountMItems(helpHandle);                    /* The number of the item */
  699.     
  700.     DrawMenuBar();
  701.     GetCurrentProcess(&gOurSN);                             /* Get our process serial number for later use, if needed */
  702.     
  703. }
  704.